import java.util.HashSet;
import java.util.Set;

/**
 * 哈希-两个数组的交集-力扣349
 */

public class Practice_25 {
    public static void main(String[] args) {
        int[] nums1 = {3};
        int[] nums2 = {2, 2, 3, 6};

        int[] r = intersection(nums1, nums2);
    }

    public static int[] intersection(int[] nums1, int[] nums2) {
        if (nums1 == null | nums1.length == 0 | nums2 == null || nums2.length == 0) {
            return new int[0];
        }

        Set<Integer> reset = new HashSet<>();

        Set<Integer> set = new HashSet<>();

        int length1 = nums1.length;
        for (int i = 0; i < length1; i++) {
            set.add((Integer) nums1[i]);
        }

        for (int j = 0; j < nums2.length; j++) {
            if (set.contains(nums2[j])) {
                reset.add(nums2[j]);
            }
        }

        int[] result = new int[reset.size()];
        int m = 0;
        for (Integer value : reset) {
            result[m] = value;
            m = m + 1;
        }
        return result;
    }
}
